<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    Username:"",
    realname:"",
    Mobile:null,
    Status:null,
    RoleIds:[],
    Note:"",
  }),
  roles: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const rolesSelect = ref(props.roles);
const { switchStyle } = usePublicHooks();

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="80px">
    <el-row :gutter="30">
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="账户名" prop="Username">
          <el-input v-model="newFormInline.Username" clearable placeholder="请输入账户名" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="姓名" prop="realname">
          <el-input v-model="newFormInline.realname" clearable placeholder="请输入姓名" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="手机号码" prop="Mobile">
          <el-input type="number" v-model="newFormInline.Mobile" clearable placeholder="请输入手机号码" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="状态" prop="Status">
          <el-switch v-model="newFormInline.Status" inline-prompt :active-value="1" :inactive-value="0" active-text="启用"
            inactive-text="停用" :style="switchStyle" />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="角色" prop="RoleIds">
          <el-select v-model="newFormInline.RoleIds" multiple placeholder="请选择角色" style="width: 100%">
            <el-option v-for="item in rolesSelect" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="描述" prop="Note">
          <el-input v-model="newFormInline.Note" clearable placeholder="请输入描述" type="textarea" />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
  margin-right: 16px;
}
</style>
